package net.lab1024.sa.admin.module.business.exam.service;

import java.util.List;
import net.lab1024.sa.admin.module.business.exam.dao.QuestionsaDao;
import net.lab1024.sa.admin.module.business.exam.domain.entity.QuestionsaEntity;
import net.lab1024.sa.admin.module.business.exam.domain.form.add.QuestionsaAddForm;
import net.lab1024.sa.admin.module.business.exam.domain.form.query.QuestionsaQueryForm;
import net.lab1024.sa.admin.module.business.exam.domain.form.update.QuestionsaUpdateForm;
import net.lab1024.sa.admin.module.business.exam.domain.vo.QuestionsaVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 日历明细 Service
 *
 * @Author AKITA
 * @Date 2025-06-06 11:11:41
 * @Copyright AKITA
 */

@Service
public class QuestionsaService {

    @Resource
    private QuestionsaDao questionsaDao;

    /**
     * 分页查询
     */
    public PageResult<QuestionsaVO> queryPage(QuestionsaQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<QuestionsaVO> list = questionsaDao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(QuestionsaAddForm addForm) {
        QuestionsaEntity questionsaEntity = SmartBeanUtil.copy(addForm, QuestionsaEntity.class);
        questionsaDao.insert(questionsaEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     */
    public ResponseDTO<String> update(QuestionsaUpdateForm updateForm) {
        QuestionsaEntity questionsaEntity = SmartBeanUtil.copy(updateForm, QuestionsaEntity.class);
        questionsaDao.updateById(questionsaEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     */
    public ResponseDTO<String> batchDelete(List<Long> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        questionsaDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Long docEntry) {
        if (null == docEntry){
            return ResponseDTO.ok();
        }

        questionsaDao.deleteById(docEntry);
        return ResponseDTO.ok();
    }
}
